﻿using System;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using netCoreStudy.Entities;
using netCoreStudy.IService;
using Quartz;

namespace netCoreStudy.Quartz
{
	//这个特性 可防止Quartz.NET尝试同时运行同一作业。
	[DisallowConcurrentExecution]
	public class SpiderPageJob : IJob
	{
		private readonly ILogger<SpiderPageJob> _logger;
		private readonly IUserService _companyService;

		public SpiderPageJob(ILogger<SpiderPageJob> logger, IUserService companyService)
		{
			_logger = logger;
			_companyService = companyService;
		}

		public async Task Execute(IJobExecutionContext context)
		{
			User company = await _companyService.GetOneByIdAsync(1);
			if (company != null)
			{
				_logger.LogInformation($"后台任务启动 {company.Name}");
			}
		}
	}
}